package com.alpha.service.config;

import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Jackson 配置
 *
 * @author chenruwan
 * @since 2022-01-01
 */
@Configuration
public class JacksonConfiguration {

    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        /*
         * 自定义序列化器，解决前端JS Long类型精度丢失问题
         * mybatis-plus Page分页的current和size是long类型，所以只设置Long.class，不设置Long.TYPE
         */
        return builder -> builder.serializerByType(Long.class, ToStringSerializer.instance);
    }
}
